#!/bin/bash

title1="显示文字“Waiting for a while….” ；长格式显示当前目录下面的文件和目录，并输出重定向到/home/file.txt文件 ；定义一个变量，名为s，初始值“Hello” ；使该变量输出重定向到/home/string.txt文件"
echo ${title}
s="Hello"
echo "Waiting for a while..."
if [ -e "/homr/file.txt" -a -f "/home/file.txt" ];then
	ls -l . > /home/file.txt
else
	touch /home/file.txt;ls -l . > /home/file.txt
fi
if [ -e "/home/string.txt" -a -f "/home/string.txt" ];then
	echo "${s}" > /home/string.txt
else
	touch /home/string.txt;echo "${s}" > /home/string.txt
fi

title2=" 编写一个shell脚本，利用for循环将当前目录下的.c文件移动到指定的目录，并按文件大小显示出移动后指定的目录的内容"
echo ${title2}

read -p "please input the name of Target directory:" dir
if [ ! -e ${dir} ];then
	mkdir -p ${dir}
fi
if [[ -e "*.c" ]];then
	for file in *.c
		do
			cp ${file} ${dir}
		done
else
	echo "No *.c files"
fi
ls -lS ${dir}


title3="利用数组形式存放10个城市的名字，然后利用for循环把它们打印出来。"
echo ${title3}
count=1
citys=(唐山 北京 天津 保定 秦皇岛 廊坊 石家庄 邯郸 承德 邢台)
for city in ${citys[@]}
        do
                echo "第${count}个城市是${city}"
                ((count++))
        done


title4="计算10的阶乘"
echo ${title4}
factorial=1
for num in `seq 1 10`
	do
		factorial=$[ ${factorial} * ${num}]
	done
echo "10! is ${factorial}"
